import { send_gateway_request } from "../libs/request";

const handleLoginResp = (resp: any) => {
  if (!resp.token) {
    throw new Error(resp.message);
  }
  // console.log('登录TOKEN'+resp.token)
  // const { token,username,user_id,updated_at,expires,created_at } = resp || {}

  return resp;
};

const login = async (data: any, headers: any) => {
  const resp = await send_gateway_request({
    method: "post",
    url: "/ecos/api_noauth/user/login",
    headers: {
      ...headers,
      // 'content-type': 'application/x-www-form-urlencoded',
    },
    params: {
      ...data,
    },
  });
  return handleLoginResp(resp);
};

export { login };
